package com.shuai.jit.controller;

import com.shuai.jit.entity.R;
import com.shuai.jit.entity.user.User;
import com.shuai.jit.service.impl.UserServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class CheckUserController {

    @Autowired
    UserServiceImpl userService;

    @ApiOperation("添加认证信息")
    @RequestMapping("/check")
    public R addCheck(@RequestBody User user){
        Integer result=userService.checkUser(user);
        if(result>0){
            return R.ok().data("user","添加认证信息成功");
        }else {
            return R.error().data("user","添加认证信息失败");
        }
    }

    @ApiOperation("更新认证信息")
    @RequestMapping("/updateCheck")
    public R updateCheck(String id,Integer approve){
        Integer result=userService.updateCheck(id,approve);
        if(result>0){
            if(approve==0){
                return R.ok().data("user","驳回请求成功");
            }else {
                return R.ok().data("user","认证成功");
            }
        }else {
            return R.error().data("user","用户认证信息失败");
        }
    }

    @ApiOperation("查找需要认证的用户")
    @RequestMapping("/getCheckUser")
    public R getCheckUser(Integer current){
        if(current==null){
            return  R.error().data("user","current为空");
        }
        return  R.ok().data("user",userService.getCheckUser(current));
    }
}
